# coding:utf-8
'''
最热APP应用
AppStore排行榜

https://www.applehunt.com/top
'''
import urllib3
from urllib3 import PoolManager
from bs4 import BeautifulSoup
import pandas as pd

http = PoolManager()
urllib3.disable_warnings()

app_items = []
result = http.request(method="GET", url="https://www.applehunt.com/top")
soup = BeautifulSoup(result.data.decode(), "html.parser")
'''
<td class="free">
<div class="app-block">
<a href="/app/1436120806" target="_blank" title="梦幻西游三维版"><div class="app-icon"><div class="app-radius-75"></div><img class="lazy" src="" data-original="" alt="梦幻西游三维版"></div></a>
<div class="app-info">
<h4><a href="/app/1436120806" target="_blank" title="梦幻西游三维版">梦幻西游三维版</a></h4>
<p>分类：游戏</p>
<p class="app-price">价格：免费</p>
</div>
</div>
</td>
'''
# pay
for item in soup.find_all("td", attrs={"class":"free"}):
    app_pic_url = item.find("img")["data-original"]
    app_name = item.find("h4").text
    app_class = item.find("p").text.replace("分类：", "")
    app_items.append([app_pic_url, app_name, app_class])

df = pd.DataFrame(app_items, columns=["应用图片URL地址", "应用", "类别"])
df.to_excel("d:/app_store.xlsx")
